{extend name="property/public/insidePageBase" /}
{block name="title"}短信日志列表{/block}
{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">手机号搜索</label>
                    <div class="layui-input-inline">
                        <input type="text" name="mobile" placeholder="请输入手机号查询" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">按日期筛选</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-inline" style="width: 180px;">
                            <input type="text" name="time" id="time" placeholder="发送时间-结束时间" class="layui-input laydate-type-start-end">
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">关键词搜索</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keywords" autocomplete="off" class="layui-input" placeholder="请输入关键词搜索信息">
                    </div>
                </div>
                <div class="layui-inline">
                    <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                </div>
            </div>
        </form>
        <script type="text/html" id="toolbar">
            <div class="layui-btn-container">
                {if $delAuth}<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>{/if}
            </div>
        </script>
        <table class="layui-hide" id="logList" lay-filter="logList"></table>
        <script type="text/html" id="tableBar">
            <div class="layui-btn-group">
                {if $delAuth}<a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</a>{/if}
            </div>
        </script>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
    <script>
        layui.use(['form', 'table','laydate'], function () {
            var $ = layui.jquery,form = layui.form, table = layui.table,laydate = layui.laydate;
            laydate.render({
                elem: '#time',type: 'date',range: true
            });
            var tableId = 'logList';
            table.render({
                elem: '#'+tableId,
                id:tableId,
                url: '{:url("propertySmsLogList")}',
                toolbar: '#toolbar',
                cols: [[
                    {type: "checkbox"},
                    {field: 'mobile', width: 120, title: '手机号'},
                    {field: 'sms_type', width: 100, title: '短信类型'},
                    {field: 'add_time', width: 160, title: '发送时间'},
                    {field: 'is_verify', width: 108, title: '验证状态', templet:function(d) {
                        if(d.is_verify === 1) {return '已验证';} else {  return '未验证';  } }},
                    {field: 'status', width: 108, title: '发送状态', templet:function(d) {
                        if(d.status === 1) { return '发送成功';  } else { return '发送失败'; } }},
                    {field: 'content', title: '短信内容'},
                    {field: 'error_msg',width: 128,title: '错误信息'}
                    {if $delAuth}
                    , {title: '操作', width: 88, toolbar: '#tableBar', align: "left"}
                    {/if}
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                height: 'full-80'
            });
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                table.reload(tableId, { page: { curr: 1} , where: data.field}, 'data');
                return false;
            });

            /**
             * toolbar监听事件
             */
            table.on('toolbar('+tableId+')', function (obj) {
                if (obj.event === 'delete') {  // 监听删除操作
                    var checkStatus = table.checkStatus(obj.config.id),data = checkStatus.data;
                    var data = checkStatus.data, id = [];
                    for (elem in data) {
                        id.push(data[elem].id);
                    }
                    if (id.length === 0) {
                        return layer.msg('请选择要删除的数据');
                    }
                    var url = '{:url("propertySmsLogDel")}';
                    layer.confirm('删除后不可恢复！  是否确认? ', {icon: 3}, function () {
                        var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, {ids: id}, function (res) {
                            layer.close(loadAdd);
                            if (res.code === 0) {
                                table.reload(tableId); //数据刷新
                                layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                }
            });

            //监听表格复选框选择
            table.on('checkbox('+tableId+')', function (obj) {
                console.log(obj)
            });

            table.on('tool('+tableId+')', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    var url = '{:url("propertySmsLogEdit")}?id='+data.id;
                    var index = layer.open({
                        title: '编辑日志', type: 2,  shade: 0.2, maxmin:true, area: ['500px', '400px'], content: url, btnAlign: 'c', btn: ['确定', '取消'], yes: function (index, layero) {
                            var iframeWindow = window['layui-layer-iframe' + index], submit = layero.find('iframe').contents().find("#submitBtn");
                            iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                                var field = data.field; //获取提交的字段
                                var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                                $.post(url, field, function (res) {
                                    layer.close(loadAdd);
                                    if (res.code === 0) {
                                        table.reload(tableId); //数据刷新
                                        layer.close(index); //关闭弹层
                                        layer.msg(res.msg, {icon: 6, offset: '15px'});
                                    } else {
                                        layer.msg(res.msg, {icon: 5, offset: '15px'});
                                    }
                                });
                            });
                            submit.trigger('click');
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                } else if (obj.event === 'delete') {
                    var url = '{:url("propertySmsLogDel")}';
                    layer.confirm('删除后不可恢复！  是否确认? ', {icon: 3}, function () {
                        var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, {ids: [data.id]}, function (res) {
                            layer.close(loadAdd);
                            if (res.code === 0) {
                                table.reload(tableId); //数据刷新
                                layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                }
            });

        });
    </script>
{/block}